package experiment.e04.code;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/9/29 23:14
 * @package experiment.e04.code
 * @description 文件说明
 */

public class E04 {
    // 测试主函数
    public static void main(String[] args) {
        Simulator2 simulator = new Simulator2();
        simulator.playSound(new Dog2());
        simulator.playSound(new Cat2());
    }
}

/**
 * 动物接口
 */
interface Animal2 {
    public  abstract void cry();
    public abstract String getAnimalName();
}

/**
 * 模拟器类
 */
class Simulator2 {
    public void playSound(Animal2 animal){
        System.out.print("现在播放" + animal.getAnimalName() + "类的声音\t");
        animal.cry();
    }
}

/**
 * 狗类
 */
class Dog2 implements Animal2 {

    @Override
    public void cry() {
        System.out.println("汪汪汪");
    }

    @Override
    public String getAnimalName() {
        return "狗🐕";
    }
}

/**
 * 猫类
 */
class Cat2 implements Animal2 {

    @Override
    public void cry() {
        System.out.println("喵喵喵");
    }

    @Override
    public String getAnimalName() {
        return "猫🐱";
    }
}



